﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Axis.Dao.Product;
using Axis.BusinessObject.Product;

namespace Sotipha.Web.Views.Home
{
    public partial class ucBESTSELLERS : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string Result = "";
            string ImageProduct = "";
            CProductDao coreProductGroup = new CProductDao();
            IList<CProduct> listProduct = coreProductGroup.GetProductByCondition("<InputValue Context=\"BESTSELLERS\"/>");
            string PatternImage = "<li><a href=\"{0}\">"
                + "<img src=\"{1}\" /></a> <a class=\"nm\" href=\"{0}\">{2}</a> </li>";
            if (listProduct == null) return;
            if (Session["lang"].ToString() == "vi")
            {
                ltrBestSellers.Text = "Sản phẩm bán chạy nhất";
                foreach (var item in listProduct)
                {
                    var Link = BuildLink(item);
                    ImageProduct += string.Format(PatternImage, Link, item.Thumbnail, item.Intro_VN);
                }
            }
            else
            {
                foreach (var item in listProduct)
                {
                    var Link = BuildLink(item);
                    ImageProduct += string.Format(PatternImage, Link, item.Thumbnail, item.Intro_EN);
                }
            }
            ltrImage.Text = ImageProduct;
        }
        public string BuildLink(CProduct Item)
        {
            string Result = "";
            switch (Item.ProductTypeID)
            {
                case 1:
                    Result = "../Towntalk/ProductDetail.aspx?ID=" + Item.ID;
                    break;
                case 2:
                    Result = "../Lacquerware/ProductDetail.aspx?ID=" + Item.ID;
                    break;
                case 3:
                    Result = "../Gifts/ProductDetail.aspx?ID=" + Item.ID;
                    break;
                case 4:
                    Result = "../Sale/ProductDetail.aspx?ID=" + Item.ID;
                    break;
            }
            return Result;
        }
    }
}